<template>
  <drop-wrap :data="data" :index="index" :element="element">
    <el-form-item
      v-if="store.componentsMap[element.key]"
      :id="element.cid"
      :prop="prop"
      :rules="element.rules"
      :label="element.options.label"
    >
      <el-time-picker
        arrow-control
        v-model="element.options.defaultValue"
        v-bind="inputAttrs"
      >
      </el-time-picker>
    </el-form-item>
  </drop-wrap>
</template>

<script>
import { ruleCheck } from "@/low-code/utils/store.js";
import { ruleCheckOringin } from "@/low-code/utils/enumeration.js";
export default {
  props: ["element", "data", "index"],
  data() {
    return {};
  },
  computed: {
    prop() {
      return `${this.element.fullModelTag}`;
    },
    store() {
      return this.element.getRoot();
    },
    inputAttrs() {
      const attrsConfig = {
        readonly: this.element.options.readonly,
        disabled: this.element.options.disabled,
        clearable: this.element.options.clearable,
        "value-format": this.element.options.showType,
        format: this.element.options.format,
        placeholder: this.element.options.placeholder,
        "picker-options": this.element.options.selectableRange,
      };
      return Object.assign({}, attrsConfig);
    },
    rules() {
      let _this = this;
      const rules = [{ validator: ruleCheck.noCheck(), trigger: "blur" }];
      this.element.rules.map((item) => {
        if (item.ruleType == ruleCheckOringin.SELECT) {
          item.validator = ruleCheck.validatePass(item.validatorType);
          rules.push(item);
        } else {
          rules.push({
            validator:function (rule, value, callback){
              let form= _this.store.models
              item.validator&&eval(item.validator)(rule, value, callback,form);
            },
            trigger: "change",
          });
        }
      });
      return rules;
    },
  },
};
</script>

<style scoped>
.el-date-editor {
  width: 100%;
}
</style>